home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / fc.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  65 lines

  1. /* Test class Fraction
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    fc.c,v $
  26.  * Revision 3.0  90/05/20  00:29:06  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/fc.c,v 3.0 90/05/20 00:29:06 kgorlen Rel $";
  31.  
  32. #include <osfcn.h>
  33. #include "Fraction.h"
  34.  
  35. Fraction readf(istream& strm)
  36. {
  37.     char delim;
  38.     int u,v;
  39.     strm >> u; strm.get(delim); strm >> v;
  40.     if (strm.eof()) exit(0);
  41.     return Fraction(u,v);
  42. }
  43.  
  44. main()
  45. {
  46.     Fraction x,y,z;
  47.     char op;
  48.     while (YES) {
  49.         cout << "Enter x: "; x = readf(cin); cout << endl;
  50.         cout << "Enter y: "; y = readf(cin); cout << endl;
  51.         cout << "Enter op: "; cin >> op; cout << endl;
  52.         switch (op) {
  53.             case '+': { z = x+y; break; }
  54.             case '-': { z = x-y; break; }
  55.             case '*': { z = x*y; break; }
  56.             case '/': { z = x/y; break; }
  57.             case '<': { z = x<y; break; }
  58.             case '>': { z = x>y; break; }
  59.             case '=': { z = x==y; break; }
  60.             default: { cout << "Incorrect op" << endl; continue; }
  61.         }
  62.         cout << x << ' '; cout.put(op); cout << ' ' << y << " = " << z << endl;
  63.     }
  64. }
  65.